package com.andy.blog.admin.controller;

import com.andy.blog.admin.dto.CommentReplyDTO;
import com.andy.blog.admin.dto.RecentCommentDTO;
import com.andy.blog.admin.dto.ReplyDTO;
import com.andy.blog.admin.service.CommentReplyBusService;
import com.andy.blog.common.annotation.Log;
import com.andy.blog.common.enums.BusinessTypeEnum;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.vo.CommentReplyVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by andy on 2023/7/28 11:37
 */
@RestController
@Api(tags = "评论回复")
@ApiSupport(author = "Andy")
public class CommentReplyController {

    @Resource
    private CommentReplyBusService commentReplyBusService;


    /**
     * 新增评论
     */
    @Log(title = "评论管理", businessType = BusinessTypeEnum.INSERT)
    @PostMapping("/portal/commentReply/addCommentReply")
    public GeneralResponseResult<Void> addCommentReply(@RequestBody CommentReplyVO commentReplyVO) {
        commentReplyBusService.addCommentReply(commentReplyVO);
        return GeneralResponseResult.success();
    }

    /**
     * 分页查询
     */
    @GetMapping("/portal/commentReply/listPage")
    public GeneralResponseResult<PageUtilsDTO<CommentReplyDTO>> listPage(CommentReplyVO commentReplyVO) {
        return GeneralResponseResult.success(commentReplyBusService.listPage(commentReplyVO));
    }


    /**
     * 查看回复评论
     *
     * @param commentId 评论id
     */
    @ApiOperation(value = "查看回复评论")
    @ApiOperationSupport(author = "andy1")
    @GetMapping("/commentReply/{commentId}")
    public GeneralResponseResult<List<ReplyDTO>> listReply(@PathVariable("commentId") Long commentId) {
        return GeneralResponseResult.success(commentReplyBusService.listReply(commentId));
    }

    /**
     * 查看最新评论
     */
    @ApiOperation("查看最新评论")
    @GetMapping("/portal/recent/comment")
    public GeneralResponseResult<List<RecentCommentDTO>> listRecentCommentVO() {
        return GeneralResponseResult.success(commentReplyBusService.listRecentCommentVO());
    }
}
